package com.yupi.shortchain.utils;

import com.yupi.shortchain.config.DistributedIdGenerator;
import javax.annotation.Resource;

public class Base62Converter {

    @Resource
    private DistributedIdGenerator distributedIdGenerator;
    private Base62Converter() {
        throw new IllegalStateException("Utility class");
    }

    // 定义 Base62 字符表
    static final char[] BASE62_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".toCharArray();

    public static String toBase62(long hash) {
        // 存储转换后的 Base62 字符串
        StringBuilder result = new StringBuilder();

        // 62进制的基数
        int radix = 62;

        // 将哈希值转换为正数处理
        hash = Math.abs(hash);

        // 将哈希值转换为62进制
        while (hash > 0) {
            int remainder = (int) (hash % radix);
            result.insert(0, BASE62_CHARS[remainder]);
            hash = hash / radix;
        }

        return result.toString();
    }

//long hash = LongHashFunction.wy_3().hashChars("hello");
//    public static void main(String[] args) {
//        String url = "https://github.com/OpenHFT/Zero-Allocation-Hashing?tab=readme-ov-file";
//        LongHashFunction hashFunction = LongHashFunction.wy_3();
//        long hashedChars = hashFunction.hashChars(url);
//        System.out.println("hashedChars: " + hashedChars);
//        String base62 = toBase62(hashedChars);
//        System.out.println("base62: " + base62);
//    }




}


